"""
回合制游戏:两人进行到一个房间,相互攻击
创建Role类
    属性:名字,血量,积分,
    方法:攻击a.attack(b)随机掉血(10-30)
    装备
房间信息
    名称 编号 成员 最大人数
    加入房间,房间满员自动开始游戏
Game
    交互式菜单
"""
import random
class Room():
    def __init__(self,ID,name,user_lst,max_number:2):
        self.ID = ID
        self.name = name
        self.user_lst = user_lst
        self.max_number = max_number
    def add_room(self,user):
        if len(self.user_lst)<= self.max_number:
            self.user_lst.append(user)
            print(f"{user}成功进入房间!")
    def see_room_user(self):
        print(f"当前房间人数为{len(self.user_lst)}")
        for i in self.user_lst:
            print(f"当前房间成员有{i.username}")
    def see_room_number(self):
        return len(self.user_lst)

class Role():
    INIT_HP = 100
    def __init__(self,username,hp = None,max_attack=None):
        self.username = username
        if hp:
            self.hp = hp
        else:
            self.hp = self.__class__.INIT_HP
        #攻击上限
        self.max_attack = max_attack

    def attack(self,user):
        if self.is_alive():
            if user.is_alive():
                damage = random.randint(1, self.max_attack)
                print(f"{self.username}触发攻击效果,对方将随机掉血...")
                user.hp -= damage
                print(f"{self.username}{self.hp}对{user.username}{user.hp}造成{damage}伤害\n")
            else:
                print(f"{user.username}已经阵亡")
        else:
            print(f"{self.username}已经阵亡!不能攻击他人")
    def is_alive(self):
        return self.hp>0

A = Role("周雨晴",100,30)
B = Role("夏经纬",100,40)
# C = Role("游淑娟",100,30)
# D = Role("全妍",100,40)
room1 = Room("001","开心家园",{A,B},2)
if room1.see_room_number() == room1.max_number:
    print(f"{room1.ID}号{room1.name}房间,游戏开始!")
    room1.see_room_user()
    while True:
        A.attack(B)
        B.attack(A)
        # C.attack(D)
        # D.attack(A)
        if not A.is_alive() and B.is_alive():
            print(f"游戏结束,{B.username}胜利")
            break
        if not B.is_alive()  and A.is_alive():
            print(f"游戏结束,{A.username}胜利")
            break

